<?php

/**
 *
 *
 * @version $Id$
 * @copyright 2013
 */

namespace com\org\web\tpl\utils {
	class Collection implements \Iterator, \Countable {
		/**
		 * List of data
		 */
		private $_content = NULL;

		/**
		 * Position of the iterator
		 */
		private $_index = 0;

		public function __construct(&$content) {
			if (!is_array($content))
				throw new \Exception("Collection::__construct:$content is not an array.");
			$this->_content = $content;
		}

		/**
		 * Retrieve the current record
		 */
		public function current() {
			return $this->_content[$this->_index];
		}

		/**
		 * Return the current key index
		 */
		public function key() {
			return $this->_index;
		}

		/**
		 * Increment the iterator index
		 */
		public function next() {
			++$this->_index;
		}

		/**
		 * Reset the position
		 */
		public function rewind() {
			$this->_index = 0;
		}

		/**
		 * Validate whether a record at current
		 * position exists
		 */
		public function valid() {
			return isset($this->_content[$this->_index]);
		}

		/**
		 * Return the total number of users
		 */
		public function count() {
			return count($this->_content);
		}
	}
}
?>